from CaiLiaoRead import read_sanhao
# 创建格式转换函数，将['78 40 90 71', '91 42 91 82', '36 80 65 44', '69 96 92 74']转换为二维浮点数列表
def convert_to_float(lines:list):
    lines = [line.split() for line in lines]
    # lines = [[float(x) for x in line] for line in lines]
    # 遍历这二维数组中的每个元素，将其转换为浮点数
    lines = [[float(x) for x in line] for line in lines]
    return lines

# 创建清洗函数
def clean_lines_drity(lines:list):
    lines = [line.strip() for line in lines]
    return lines
def main_preprocess():
    lines_dirty = read_sanhao("./7-深度学习基本原理-三好学生案例/sanhao.txt")
    lines_cleaed = clean_lines_drity(lines_dirty)
    lines_cleaed = convert_to_float(lines_cleaed)
    return lines_cleaed
    
if __name__ == "__main__":
    from CaiLiaoRead import read_sanhao
    lines_dirty = read_sanhao("./7-深度学习基本原理-三好学生案例/sanhao.txt")
    lines_cleaed = clean_lines_drity(lines_dirty)
    lines_cleaed = convert_to_float(lines_cleaed)
    print("预处理后",lines_cleaed[1:5])